﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Setting_add_position : System.Web.UI.Page
{
	LogicLayer mgr = new LogicLayer();

	protected SYS_Position curPosition;
	protected string tip = "";
	protected string curPositionID = string.Empty; 

    protected void Page_Load(object sender, EventArgs e)
    {
		curPositionID = Request.QueryString["id"] + "";

		if(!string.IsNullOrEmpty(curPositionID))
			curPosition = mgr.GetSYS_Position(curPositionID);
		if(curPosition == null)
			curPosition = new SYS_Position();

		if (IsPostBack)
		{
			if (string.IsNullOrEmpty(curPositionID))
			{
				SYS_Position Position = new SYS_Position();
				Position.PositionID = Guid.NewGuid().ToString();
				Position.Name = Request.Form["positionName"];

				if (mgr.AddSYS_Position(Position))
					Response.Write("<script>window.opener.location.reload();window.close();</script>");
				else
					tip = "保存失败!";
			}
			else
			{
				SYS_Position Position = mgr.GetSYS_Position(curPositionID);
				Position.Name = Request.Form["positionName"];

				if (mgr.UpdateSYS_Position(Position))
					Response.Write("<script>window.opener.location.reload();window.close();</script>");
				else
					tip = "保存失败!";
			}
		}
    }
}